﻿using System.Collections.Generic;

namespace BankSystem
{
    public class Bank
    {
        List<Account> Accounts = new List<Account>();

        public Account OpenAccount(string id, string pwd, decimal money)
        {
            Account account = new Account(id, money, pwd);
            Accounts.Add(account);
            return account;
        }

        public Account OpenAccount(string id, string pwd, decimal money, int credit)
        {
            CreditAccount account = new CreditAccount(id, money, pwd, credit);
            Accounts.Add(account);
            return account;
        }

        public bool CloseAccount(Account account)
        {
            int index = Accounts.IndexOf(account);
            if (index < 0) return false;
            Accounts.Remove(account);
            return true;
        }

        public Account FindAccount(string id, string pwd)
        {
            foreach (Account account in Accounts)
            {
                if (account.IsMatch(id, pwd))
                {
                    return account;
                }
            }
            return null;
        }

    }
}
